package com.bgybmi.thread;

import com.bgybmi.sendtoken.SendTokenAgentIdApi;
import com.jfinal.kit.PropKit;
import com.jfinal.qyweixin.sdk.api.ApiConfigKit;
import com.jfinal.qyweixin.sdk.api.ApiResult;
import com.jfinal.qyweixin.sdk.api.SendMessageApi;
import com.jfinal.qyweixin.sdk.msg.send.QiYeTextMsg;
import com.jfinal.qyweixin.sdk.msg.send.Text;

public class SendMsg extends Thread{
    
	private String msg;
	
	private String user;
	
	private String agentId;
	
	public SendMsg(){
		
	}
	
    public SendMsg(String user,String msg,String agentId) {
		this.msg = msg;
		this.user=user;
		this.agentId=agentId;
	}

	@Override
    public void run() {
		sendTextMssage(user,msg,agentId);
		// sendTextMssage(msg);
    }	
	
	/**
	 * 发送文本消息 未成功
	 * 
	 * //ApiConfigKit.getAccessTokenCache();
	 */
	public void sendTextMssage(String user,String msg,String agentId) {
		
		QiYeTextMsg text = new QiYeTextMsg();
		//PropKit.get("agentId")
		text.setAgentid(agentId);//获取代理id
		text.setText(new Text(msg)); //发送的信息
		text.setSafe("0");      //是否安全消息
		System.out.println("发送用户"+user);
		text.setTouser(user); //发送的用户
//发送信息的终端用户
		//ApiConfigKit.getAccessTokenCache();
		ApiResult sendTextMsg = SendTokenAgentIdApi.sendTextMsg(text,agentId);
		//ApiResult sendTextMsg = SendMessageApi.sendTextMsg(text);
		System.out.println("消息发送结果给用户: " + sendTextMsg.getJson());	
	}
}
